﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class Home : System.Web.UI.Page
{
    protected void onInit(EventArgs e)
    {
        //base.OnInit(e);
        //if (!IsPostBack)
        //{
        //    Button btnClickMe = new Button();
        //    btnClickMe.Text = "Click me";
        //    Menu_Default.Controls.Add(btnClickMe);
            
        //}
        //else
        //{
        //    Label label = new Label();
        //    Menu_Default.Controls.Add(label);
        //    label.Text = "TESTEEEEEEEEEEEEEEEEEE";
        //}
    }

    protected override void OnLoad(EventArgs e)
    {
        //base.OnLoad(e);
        if (Session["Email"] == null)
        {
        }
        else if (Session["Nivel"] == null) // É cliente
        {
            Literal lit = new Literal();
            lit.Text = "<div class=\"box\"><h3>Funcionalidades</h3><ul class=\"bottom\"><li class=\"first\"><a href=\"SubmeterPedido.aspx\">Submeter Pedido</a></li><li><a href=\"InfoCliente.aspx\">Informação do Cliente</a></li></ul></div>";
            Menu_Default.Controls.Add(lit);
        }
        else if (Session["Nivel"].ToString().Equals("6"))
        {
            Literal lit = new Literal();
            lit.Text = "<div class=\"box\"><h3>Funcionalidades</h3><ul class=\"bottom\"><li class=\"first\"><a href=\"SubmeterPedido.aspx\">Submeter Pedido</a></li><li><a href=\"RegistarCliente.aspx\">Registar Cliente</a></li><li><a href=\"ConsultarPlaneamentoGeral.aspx\">Consultar Planeamento Geral</a></li></ul></div>";
            Menu_Default.Controls.Add(lit);
        }
        else if (!Session["Nivel"].ToString().Equals("6"))
        {
            Literal lit = new Literal();
            lit.Text = "<div class=\"box\"><h3>Funcionalidades</h3><ul class=\"bottom\"><li class=\"first\"><a href=\"ConsultarPlaneamentoPessoal.aspx\">Consultar Planeamento Pessoal</a></li><li><a href=\"ConsultarPlaneamentoGeral.aspx\">Consultar Planeamento Geral</a></li><li><a href=\"RegistarTarefas.aspx\">Registar Tarefas Realizadas</a></li></ul></div>";
            Menu_Default.Controls.Add(lit);
        }
    }

    protected void MensagemErro()
    {
        if (Session["Erro"] != null)
        {
            Literal lit = new Literal();
            lit.Text = "<ul id=\"menu2\"><li>" + Session["Erro"].ToString() + "</li></ul>";
            PanelMsg.Controls.Add(lit);
            Session["Erro"] = null;
        }
        if (Session["Sucesso"] != null)
        {
            Literal lit = new Literal();
            lit.Text = "<ul id=\"menu3\"><li>" + Session["Sucesso"].ToString() + "</li></ul>";
            PanelMsg.Controls.Add(lit);
            Session["Sucesso"] = null;
        }
    }

    //// a Property that manages a counter stored in ViewState
    //protected int NumberOfControls
    //{
    //    get { return (int)ViewState["NumControls"]; }
    //    set { ViewState["NumControls"] = value; }
    //}

    //protected void Page_Load(object sender, EventArgs e)
    //{
    //    if (!Page.IsPostBack)
    //    {
    //        //Initiate the counter of dynamically added controls
    //        this.NumberOfControls = 0;
    //        addSomeControl();
    //    }
    //    else
    //        //Controls must be repeatedly created on postback
    //        this.createControls();
    //}

    //// This routine creates the controls and assigns a generic ID

    //private void createControls()
    //{
    //    int count = this.NumberOfControls;

    //    System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");

    //    for (int i = 0; i < count; i++)
    //    {
    //        TextBox tx = new TextBox();
    //        tx.ID = "ControlID_" + i.ToString();
    //        //Add the Controls to the container of your choice

    //        //Page.Controls.Add(tx);
    //        div.Controls.Add(tx);

            
    //    }
    //}

    //// example of dynamic addition of controls
    //// note the use of the ViewState variable
    //private void addSomeControl()
    //{
    //    TextBox tx = new TextBox();
    //    tx.ID = "ControlID_" + NumberOfControls.ToString();

    //    Page.Controls.Add(tx);
    //    this.NumberOfControls++;
    //}

}